<?php defined('_JEXEC') or die('Restricted access');
$item = $this->auction;
$template = "templates/tpl_automobil/";
$user = JFactory::getUser();
$db = JFactory::getDBO();
$q = "SELECT image, image1, image2, image3, image4 FROM #__pr_product WHERE id = ".$item->product_id;
$db->setQuery($q);
$imageList = $db->loadRow();
$imgNum = 0;
foreach($imageList as $image){
	if($image) $imgNum++;
}
$query = "SELECT id, name FROM #__pr_image WHERE product_id = ".$item->product_id;
$db->setQuery($query);
$images = $db->loadObjectList();
$imgNum += count($images);

$query = "SELECT id FROM #__auction WHERE product_id = ( SELECT p.id FROM #__pr_product p INNER JOIN #__auction a ON p.id = a.product_id WHERE p.katno > ".$item->katno." AND p.bought = 0 AND a.closed = 0 AND a.published = 1 ORDER BY p.katno ASC LIMIT 0,1)";
$db->setQuery($query);
$next = $db->loadResult();
$db->setQuery("SELECT auction_date FROM #__auction_date WHERE id = 1");
$auction_date = $db->loadResult();
$auctionDateArr = explode('-', $auction_date);

$document = JFactory::getDocument();
$document->setTitle('Dansk Automobil Børs - Online auktion - '.$item->katno .'-'. $item->model);
?>
<link rel="stylesheet" type="text/css" href="<?php echo $template;?>fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<link rel="stylesheet" type="text/css" href="<?php echo $template;?>css/nivo-slider.css" media="screen" />
<script type="text/javascript" src="<?php echo $template;?>fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="<?php echo $template;?>fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script src="<?php echo $template;?>js/jquery.json-2.2.min.js"></script>
<script type="text/javascript" src="<?php echo $template;?>js/jquery.nivo.slider.pack.js"></script>
<script language="javascript">
jQuery(document).ready(function(){
	$('#slider').nivoSlider({
		effect:'random',
		slices:15,
		boxCols: 8,
		boxRows: 4, 
		animSpeed:500,
		pauseTime:5000, 
		controlNav:false,
		directionNav:false
	});
		
	jQuery("#mycarouse").jCarouselLite({
		btnNext: ".next1",
		btnPrev: ".prev1",
		visible : 6,
		scroll: 1,
		speed : 400
	});
	
	jQuery("a[rel=example_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Billede ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
});	
</script>
<style>
.init_img{
	display:inline-block;
	height:61px;
	width:98px;
}
#fancybox-title{display:none !important}
</style>
<div class="fullsite" style="width:100%">
<p>
	<span class="float_left f28"><?php echo $item->katno;?> - <?php echo $item->model;?></span>
    <span class="link-login"><a href="index.php?option=com_user&view=user&layout=profile&Itemid=13"><?php if($user->guest==0) {echo  "Min Profil";} ;?></a><a href="index.php?option=com_user&view=login&task=logout&Itemid=13" class="m12l"><?php if($user->guest==0) {echo  "Log ud";};?></a></span>
</p>
<div class="cb"></div>
<div class="tt m10b"></div>

<div class="p5t">
	<div class=" p15t">
    	<div class="w462 float_left">
        	
        	<div class="box_katalog">
            	<div id="slider" class="nivoSlider">
                	<?php if($item->image){?>
					<?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image."&w=616&h=406&zc=1' />";?>
                    <?php }?>
                    <?php if($item->image1){?>
					<?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image1."&w=616&h=406&zc=1' />";?>
                    <?php }?>
                    <?php if($item->image2){?>
					<?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image2."&w=616&h=406&zc=1' />";?>
                    <?php }?>
                    <?php if($item->image3){?>
					<?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image3."&w=616&h=406&zc=1' />";?>
                    <?php }?>
                    <?php if($item->image4){?>
					<?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image4."&w=616&h=406&zc=1' />";?>
                    <?php }?>
                    <?php foreach($images as $image){?>
                    <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->name."&w=616&h=406&zc=1' />";?>
                    <?php }?>
               	</div>
            </div>
            <div class="w451">
            	<?php /*if($imgNum > 4){?>
              	<div class="nav_prev"><a class="prev1" href="javascript:;"><img src="<?php echo $template;?>images/icon_prev1.png.jpg"></a></div>
                <?php }?>
              	<!--<div id="mycarouse" class="thunb_katalog float_left" style="overflow: hidden;">-->
                <div class="thunb_katalog float_left" style="overflow: hidden;">
                    <ul class="list_img">
                    	<?php if($item->image){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false).'components/com_ecommerce/imgupload/'.$item->image;?>" title="" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image."&w=115&h=71&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php if($item->image1){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$item->image1;?>" class="init_img" >
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image1."&w=115&h=71&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php if($item->image2){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$item->image2;?>" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image2."&w=115&h=71&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php if($item->image3){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$item->image3;?>" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image3."&w=115&h=71&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php if($item->image4){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$item->image4;?>" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image4."&w=115&h=71&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php foreach($images as $itemImage){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$itemImage->name;?>" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$itemImage->name."&w=98&h=61&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                    </ul>
                	<div class="cb"></div>
              	</div>
                <?php if($imgNum > 4){?>
              	<div class="nav_next"><a class="next1" href="javascript:;"><img src="<?php echo $template;?>images/icon_next1.png.jpg" /></a></div>
                <?php }*/?>
              	<div class="cb"></div>
            </div>
             <!--<div class="box_katalog m20t m20b">
				 <object width="450" height="336" border="0" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
                    <param value="clientView.swf" name="movie">
                    <param value="transparent" name="wmode">
                    <embed width="450" height="336" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/get/flashplayer" src="clientView.swf" />
                </object>
			</div>-->
		</div>
        <div class="w276 float_right">
			<div class="box_derip_katalog1 box_text_katalog_detail" style="width:336px;">
            <div class="title_text_katalog">Tilmelding af bil Min</div>
              <div class="p10">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <!--<tr>
                  	<td colspan="2" align="left"><a onclick="postFacebookWallDetail('<?php echo "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];?>')" href="javascript:void(0);"><img src="images/sharefb.jpg" alt=""/></a></td>
                  </tr>-->
                  <tr>
                    <td width="35%"><strong>Tilmelding af bilen Biltype: </strong></td>
                    <td width="65%"><?php echo $item->car_type;?></td>
                  </tr>
                  <tr>
                    <td><strong>Mærke/Model:</strong></td>
                    <td><?php echo $item->model;?></td>
                  </tr>
                  <tr>
                    <td><strong>Brændstof:</strong></td>
                    <td><?php echo $item->fuel;?></td>
                  </tr>
                  <tr>
                    <td><strong>1st Reg.: </strong></td>
                    <td><?php echo $item->register_day;?></td>
                  </tr>
                  <tr>
                    <td><strong>Seneste syn:</strong> </td>
                    <td><?php echo $item->view_day;?></td>
                  </tr>
                  <tr>
                    <td><strong>Skal synes: </strong></td>
                    <td><?php if($item->registry) echo "Ja"; else echo "Nej";?></td>
                  </tr>
                  <tr>
                    <td><strong>Stand/Kategori:</strong></td>
                    <td><?php echo $item->stand;?></td>
                  </tr>
                  <tr>
                    <td><strong>Km.stand: </strong></td>
                    <td><?php echo $item->km;?></td>
                  </tr>
                   <tr>
                    <td><strong>Registeringsnummer: </strong></td>
                    <td><?php echo $item->carid;?></td>
                  </tr>
                </table>
              </div>
            </div>
            
            <div class="cb"></div>
            <div class="m20t"></div>
                     
             <div class="box_price1"><span class="font18">Bud Sum</span> <span class="font27"><strong>DKK <span id="currentPriceLabel"></span>,-</strong></span></div>
          <p class="cb"></p>
        </div>
    </div>
</div>
</div>
<input type="hidden" id="currentPrice" value="<?php echo $item->currentprice;?>" />
<script language="javascript" type="text/javascript">
jQuery(document).ready(function(){
	jQuery("#header").css('display','none');
	jQuery(".w246").css('display','none');
	jQuery(".w246").css('width','0px');
	jQuery(".w739").css('width','100%');
	jQuery(".p80t").css('display','none');
	jQuery("#footer").css('display','none');
	jQuery("#currentPriceLabel").html(jQuery("#currentPrice").val());
	var i = 1;
	loadPrice = function() {
		jQuery.ajax({
			type: 'POST',
			url: ('<?php echo $this->baseurl ?>/index.php?option=com_auction&task=loadPrice'),
			data: {auc_id: <?php echo $item->id;?>},
			success: function(result){
				result=jQuery.evalJSON(result);
				if(parseInt(result.closed) == 0){
					if( parseInt(result.price) != parseInt( jQuery("#currentPrice").val() ) ){
						jQuery("#currentPrice").val(parseInt(result.price));
						jQuery("#currentPriceLabel").html(jQuery("#currentPrice").val());
						jQuery("#nextPrice").val(parseInt(jQuery("#currentPrice").val()) + 1000);
						jQuery("#nextPriceLabel").html(jQuery("#nextPrice").val());
						jQuery('#displayAuction').css('display','block');
					}
					loadPrice();
				} else {
					jQuery('#displayAuction').css('display','none');
					//clearInterval(intervalID);
					<?php if($next){?>
						$('#alert').html('Denne auktion er lukket');
						$('#backoverlay').show();
						$('#show_popup').show();
						setTimeout("location.href = 'index.php?option=com_auction&view=list&auc_id=<?php echo $next;?>&Itemid=10';", 2000);
					<?php } else {?>
						$('#alert').html('Denne auktion er lukket. Alle produkter der skal bortauktioneres');
						$('#backoverlay').show();
						$('#show_popup').show();
						setTimeout("close_popup()", 3000);
					<?php }?>					
				}
			},
			dataType: 'JSON'
		});
    };
	if(i){
		loadPrice();
		i = 0;
	}
});
</script>
